from odoo import fields, models, _
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT


class StationUseWizard(models.Model):
    _name = 's.station.use.report.wizard'
    _description = 'Station Use Report'

    station_id = fields.Many2one('work.station', 'Work Station')
    start_date = fields.Datetime('Start Date', required=True)
    end_date = fields.Datetime('End Date', required=True)

    def action_confirm(self):

        min_start_date = min(self.start_date, self.end_date)
        max_end_date = max(self.start_date, self.end_date)

        return {
            'name': _('Station Use Report'),
            'view_mode': 'tree',
            'res_model': 's.station.use.report',
            'type': 'ir.actions.act_window',
            'context': {
                'start_date': min_start_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
                'end_date': max_end_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
                'station_id': self.station_id.id
            },
        }